package com.weetop.aklyscan.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.bigkoo.pickerview.TimePickerView;
import com.blankj.utilcode.util.ToastUtils;
import com.classic.adapter.BaseAdapterHelper;
import com.classic.adapter.CommonRecyclerAdapter;
import com.weetop.aklyscan.R;
import com.weetop.aklyscan.base.BaseActivity;
import com.weetop.aklyscan.base.mvp.BaseModel;
import com.weetop.aklyscan.bean.BaseList;
import com.weetop.aklyscan.bean.MatterRecordListBean;
import com.weetop.aklyscan.bean.OutRecordListBean;
import com.weetop.aklyscan.presenter.RecordPresent;
import com.weetop.aklyscan.utils.BaseUtils;
import com.weetop.aklyscan.utils.MyTimePicker1;
import com.weetop.aklyscan.view.RecordView;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MatterBoxRecordListActivity extends BaseActivity<RecordPresent> implements RecordView, CommonRecyclerAdapter.OnItemClickListener {
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.txt_title)
    TextView txt_title;
    @BindView(R.id.tv_end_time)
    TextView endTimeView;
    @BindView(R.id.tv_total_num)
    TextView totalNumView;
    private CommonRecyclerAdapter<MatterRecordListBean> adapter;
    private List<MatterRecordListBean> list = new ArrayList<>();
    private String order_type, order_sn;

    @Override
    protected RecordPresent createPresenter() {
        return new RecordPresent(this, this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_matter_box_record);
        ButterKnife.bind(this);
        order_sn = getIntent().getStringExtra("order_sn");
        order_type = getIntent().getStringExtra("order_type");
        endTimeView.setText(order_sn);
        recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
        adapter = new CommonRecyclerAdapter<MatterRecordListBean>(mActivity, R.layout.item_matter_box_record, list) {
            @Override
            public void onUpdate(BaseAdapterHelper helper, MatterRecordListBean item, int position) {
                helper.setText(R.id.tv_xuhao, position + 1 + "");
                helper.setText(R.id.tv_num, item.getCount_sum());
                helper.setText(R.id.tv_time, item.getCreate_time());
                helper.setText(R.id.tv_zhongzhuan, item.getBarcode());
                helper.setText(R.id.tv_member_number, item.getApply_user_account());
            }
        };
        adapter.setOnItemClickListener(this);
        recyclerView.setAdapter(adapter);
        query();
    }

    @OnClick({R.id.iv_back, R.id.query})
    public void onViewClicked(View view) {
        int id = view.getId();
        if (R.id.iv_back == id) {
            finish();
        }else if(R.id.query == id){
            query();
        }
    }

    private void query() {
        mPresenter.Into75(order_sn);
    }

    @Override
    public void onItemClick(RecyclerView.ViewHolder viewHolder, View view, int i) {
        Intent intent = new Intent(MatterBoxRecordListActivity.this, BoxPeijianRecordDetailActivity.class);
        intent.putExtra("start_time", list.get(i).getBarcode());
        intent.putExtra("order_sn", order_sn);
        intent.putExtra("order_type", order_type);
        startActivity(intent);
    }


    @Override
    public void getInto75Success(BaseModel<BaseList<MatterRecordListBean>> o) {
        List<MatterRecordListBean> listBeans = o.getData().getList_data();
        list.clear();
        adapter.clear();
        list.addAll(listBeans);
        adapter.addAll(listBeans);
        int count = 0;
        for (MatterRecordListBean bean: o.getData().getList_data()){
            count += Integer.parseInt(bean.getCount_sum());
        }
        totalNumView.setText(count+"");
    }
}
